﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Linq;
using System.IO;
using Microsoft.Win32;

namespace DirectoryManagement
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }



        public bool ListFiles(string sourceDir)
        {
            DirectoryInfo dirInfoSource = new DirectoryInfo(sourceDir);
            if (!dirInfoSource.Exists)
            {
                System.Console.WriteLine("Source Directory does not exists ! Please check it !");
                return false;
            }


            FileInfo[] files = dirInfoSource.GetFiles();

            foreach (FileInfo file in files)
            {
                ResultText.AppendText(file.Name+"\n");
            }

            return true;
        }


        /******************递归打印目录以及其中的文件*********************/

        public bool ListDirs(string sourceDir)
        {
            DirectoryInfo dirInfoSource = new DirectoryInfo(sourceDir);
            bool bResult = true;

            if (!dirInfoSource.Exists)
            {
                System.Console.WriteLine("Source Directory does not exists ! Please check it !");
                bResult = false;
                return bResult;
            }

            if (ListFiles(sourceDir))
            {
                DirectoryInfo[] dirInfos = dirInfoSource.GetDirectories();

                foreach (DirectoryInfo dirInfo in dirInfos)
                {
                    bResult = ListDirs(dirInfo.Name);
                }
            }
            else
                bResult = false;

            return bResult;
        }


        private void SelectButton_Click(object sender, EventArgs e)
        {
            FolderBrowserDialog browseDialog = new FolderBrowserDialog();
            browseDialog.ShowDialog();
            PathText.Text = browseDialog.SelectedPath;
        }

        private void ListButton_Click(object sender, EventArgs e)
        {
            ListDirs(PathText.Text);
        }

        private void CopyButton_Click(object sender, EventArgs e)
        {
            if(ResultText.Text!="")
                Clipboard.SetDataObject(ResultText.Text); 

        }

    }

    


}
